package com.itheima12;

import java.time.LocalDateTime;
import java.time.Month;

/**
 * @author Xiao
 * @date 2021/7/21
 */
public class LocalDateTimeDemo03 {
    /**
     * 增加或减少时间的方法
     */
    public static void main(String[] args) {
        //需求：年份+1
        LocalDateTime time = LocalDateTime.of(2020,11,12,13,14,15);
        System.out.println(time);   //2020-11-12T13:14:15
        System.out.println("----------");
        LocalDateTime time2 = time.plusYears(1);
        LocalDateTime time3 = time.plusYears(-1);
        System.out.println(time2);  //2021-11-12T13:14:15
        System.out.println(time3);  //2019-11-12T13:14:15
    }

    public static void plusYear(LocalDateTime time) {
        int year = time.getYear() + 1;
        Month month = time.getMonth();
        int day = time.getDayOfMonth();
        int hour = time.getHour();
        int minute = time.getMinute();
        int second = time.getSecond();
        LocalDateTime time1 = LocalDateTime.of(year, month, day, hour, minute, second);
        System.out.println(time1);
    }
}
